﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace SimpleLiteForm.References
{
    /// <summary>
    /// The search result for references.
    /// </summary>
    public class ReferenceResult : ICloneable
    {
        /// <summary>
        /// The empty search result.
        /// </summary>
        public static readonly ReferenceResult Empty = new ReferenceResult(string.Empty, string.Empty, null);

        /// <summary>
        /// Gets or sets the title.
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// Gets or sets the content.
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// The reference URI.
        /// </summary>
        public Uri Uri { get; set; }

        /// <summary>
        /// Creates a ReferenceResult instance.
        /// </summary>
        /// <param name="title">The title of the search term or topic.</param>
        /// <param name="content">The content.</param>
        /// <param name="uri">The reference URI.</param>
        public ReferenceResult(string title, string content, Uri uri)
        {
            Title = title;
            Content = content;
            Uri = uri;
        }

        /// <summary>
        /// Filters and overwrites the content.
        /// </summary>
        public void FilterContent()
        {
            Content = Regex.Replace(Content, @"<[^>]*>", String.Empty).Trim();
            
        }

        /// <summary>
        /// Gets whether the reference result is empty.
        /// </summary>
        public bool IsEmpty
        {
            get
            {
                return Title == string.Empty && Content == string.Empty;
            }
        }

        /// <summary>
        /// Clones the object.
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            return new ReferenceResult(
                (string)Title.Clone(),
                (string)Content.Clone(),
                new Uri(Uri.OriginalString, UriKind.Absolute));
        }
    }
}
